package com.ruoyi.house_sale.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.Schemeflow;
import com.ruoyi.house_sale.service.ISchemeflowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 方案流程Controller
 * 
 * @author ruoyi
 * @date 2022-03-28
 */
@RestController
@RequestMapping("/house_sale/schemeflow")
public class SchemeflowController extends BaseController
{
    @Autowired
    private ISchemeflowService schemeflowService;

    /**
     * 查询方案流程列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:list')")
    @GetMapping("/list")
    public TableDataInfo list(Schemeflow schemeflow)
    {
        startPage();
        List<Schemeflow> list = schemeflowService.selectSchemeflowList(schemeflow);
        return getDataTable(list);
    }

    /**
     * 导入方案流程数据
     */
    @Log(title = "方案流程", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Schemeflow> util = new ExcelUtil<Schemeflow>(Schemeflow.class);
        List<Schemeflow> schemeflowList = util.importExcel(file.getInputStream());
        String message = schemeflowService.importFlow(schemeflowList, updateSupport);
        return AjaxResult.success(message);
    }

    /**
     * 导出方案流程列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:export')")
    @Log(title = "方案流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Schemeflow schemeflow)
    {
        List<Schemeflow> list = schemeflowService.selectSchemeflowList(schemeflow);
        ExcelUtil<Schemeflow> util = new ExcelUtil<Schemeflow>(Schemeflow.class);
        util.exportExcel(response, list, "方案流程数据");
    }

    /**
     * 下载方案流程模板
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:export')")
    @Log(title = "下载方案流程模板", businessType = BusinessType.EXPORT)
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Schemeflow> util = new ExcelUtil<Schemeflow>(Schemeflow.class);
        util.importTemplateExcel(response, "方案流程");
    }

    /**
     * 获取方案流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:query')")
    @GetMapping(value = "/{flowid}")
    public AjaxResult getInfo(@PathVariable("flowid") Long flowid)
    {
        return AjaxResult.success(schemeflowService.selectSchemeflowByFlowid(flowid));
    }

    /**
     * 新增方案流程
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:add')")
    @Log(title = "方案流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Schemeflow schemeflow)
    {
        //获取当前登录用户
//        LoginUser user = SecurityUtils.getLoginUser();
//        schemeflow.setUserid(user.getUserId() + "");
        schemeflow.setOprtime(new Date());
        return toAjax(schemeflowService.insertSchemeflow(schemeflow));
    }

    /**
     * 修改方案流程
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:edit')")
    @Log(title = "方案流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Schemeflow schemeflow)
    {
        return toAjax(schemeflowService.updateSchemeflow(schemeflow));
    }

    /**
     * 删除方案流程
     */
    @PreAuthorize("@ss.hasPermi('house_sale:schemeflow:remove')")
    @Log(title = "方案流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowids}")
    public AjaxResult remove(@PathVariable Long[] flowids)
    {
        return toAjax(schemeflowService.deleteSchemeflowByFlowids(flowids));
    }
}
